<!-- Ndas -->
<div class="main-window-segment" style="padding-top: none; padding-bottom: 20px;">
    <div class="container-fluid">
        <div class="row">

            <div class="col-lg-10 col-md-6 col-sm-12">
                <h2>Laporan Deviasi Satker</h2>
            </div>
                <?php
                //----------------------------------------------------
                //Development History.Revisi : 0 Kegiatan :1.mencetak hasil filter ke dalam pdf Dibuat oleh : Rifan Abdul Rachman Tanggal dibuat : 18-07-2014  File yang diubah : test.php  
                
						if (isset($this->d_bulan)) {
							$kdbulan = $this->d_bulan;
						} else {
							$kdbulan = 'null';
						}
						
						if (Session::get('role') == ADMIN || Session::get('role') == PKN || Session::get('role') == KPPN) {
							
							if (isset($this->d_kdsatker)) {
								$kdsatker = $this->d_kdsatker;
							}else{
								$kdsatker = 'null';
							}							
						}
						if (Session::get('role') == SATKER) {
							if (isset($this->d_kdsatker)) {
								$kdsatker = $this->d_kdsatker;
							}else{
								$kdsatker = Session::get('kd_satker');
							}
							
						}
                //----------------------------------------------------
				?>
            <div class="col-lg-1 col-md-3 col-sm-12" style="padding-top: 20px;">
                                <div class="btn-group-sm">
                    <button type="button" class="btn btn-default dropdown-toggle fullwidth" data-toggle="dropdown" aria-expanded="false"><span class="glyphicon glyphicon-print"></span>&nbsp; Cetak <span class="caret"></span>
                    </button>
                          <ul class="dropdown-menu" role="menu">
                            <li><a href="<?php echo URL; ?>PDF/rekapRPDAkurasiSatker_PDF/<?php echo $kdbulan . "/" . $kdsatker; ?>/PDF">PDF</a></li>
                            <li><a href="<?php echo URL; ?>PDF/rekapRPDAkurasiSatker_PDF/<?php echo $kdbulan . "/" . $kdsatker; ?>/XLS">EXCEL</a></li>
                          </ul>
                </div>
						
            </div>



			<div class="col-lg-1 col-md-3 col-sm-12" style="padding-top: 20px;">

                <button type="button" style="width: 100%" class="btn btn-default" data-toggle="modal" data-target="#modal-app-filter"><span class="glyphicon glyphicon-filter"></span> Filter</button>

            </div>
            
        </div>

        <div class="row" style="padding-top: 10px">

            <div class="col-md-6 col-sm-12">
                <?php
                if (isset($this->d_bulan)) {
                    echo "Bulan : ".Tanggal::bulan_indo($this->d_bulan);
                    $kode_bulan = $this->d_bulan;
                } else {
                    $kode_bulan = "SEMUA";
                }
                if (isset($this->d_kanwil)) {
                    foreach ($this->d_nama_kanwil as $kanwil) {
                        echo "<br/>Kanwil : ".$kanwil->get_nama_user() . " (" . substr($kanwil->get_kd_satker(),1,2) . ")";
                        $kode_kanwil = substr($kanwil->get_kd_satker(),1,2);
                    }
                } else {
                    $kode_kanwil = "SEMUA";
                }
                if (isset($this->d_nama_kppn)) {
                    foreach ($this->d_nama_kppn as $kppn) {
                        echo "<br/>".$kppn->get_nama_user() . " (" . $kppn->get_kd_satker() . ")";
                        $kode_kppn = $kppn->get_kd_satker();
                    }
                } else {
                    $kode_kppn = "SEMUA";
                }
                if (isset($this->d_kdsatker)) {
                    echo "<br/>Satker : ".$this->d_kdsatker;
                    $kode_satker = $this->d_kdsatker;
                } else {
                    $kode_satker = "SEMUA";
                }
                if (isset($this->d_akun)) {
                    echo "<br/>Akun : ".$this->d_akun;
                    $kode_akun = $this->d_akun;
                } else {
                    $kode_akun = "SEMUA";
                }
                ?>
            </div>

            <div class="col-md-6 col-sm-12" style="text-align: right;">
                <?php
                echo "<i>(Data dalam jutaan Rupiah)</i>";                
                // untuk menampilkan last_update
                if (isset($this->last_update)) {
                    foreach ($this->last_update as $last_update) {
                        echo "Update Data Terakhir (Waktu Server)<br/>" . $last_update->get_last_update() . " WIB";
                    }
                }
                
                ?>
            </div>

        </div>

    </div>
</div>
<?php
if (isset($this->data_akun)) {
    if (empty($this->data_akun)) {
        $col_akun = 1;
    } else {
        $col_akun = count($this->data_akun); 
        foreach ($this->data_akun as $value_akun) {
            $akun2[] = $value_akun->get_akun();
        }        
    }
} else {
    $col_akun = 1;
}
if (isset($this->data_dom)) {
    if (empty($this->data_dom)) {
        $col_dom = 1;
    } else {
        $col_dom = count($this->data_dom); 
        foreach ($this->data_dom as $value_dom) {
            $dom2[] = $value_dom->get_dom();
        }        
    }
} else {
    $col_dom = 1;
} 
if (isset($this->data)) {
    if (empty($this->data)) {
        $col = 1;
    } else {
        $col = count($this->data); 
        $no_data_array = 0;
        foreach ($this->data as $value) {
            $data_array[$no_data_array]["hari"] = $value->get_dom();
            $data_array[$no_data_array]["akun"] = $value->get_akun();
            $data_array[$no_data_array]["rpd"] = $value->get_rpd_1();
            $data_array[$no_data_array]["realisasi"] = $value->get_rpd_2();
            $data_array[$no_data_array]["deviasi"] = $value->get_rpd_3();
            $no_data_array++;
        }        
    }
} else {
    $col_dom = 1;
}    
?>
<!-- Tabel -->
<div id="table-container" class="wrapper">
    <table class="table table-bordered">
        <!--baris pertama-->
        <thead>
            <tr>
                <th rowspan = '2'>Tanggal</th>
                <th rowspan = '2'>Uraian</th>
                <th colspan = '<?php echo $col_akun; ?>'>Akun</th>
                <th rowspan = '2'>Deviasi Harian</th>
            </tr>
            <tr>
                <?php
                    if (isset($this->data_akun)) {
                        if (empty($this->data_akun)) {
                            echo "<th>-</th>";
                        } else {
                            foreach ($this->data_akun as $value_akun) {
                                echo "<th>".$value_akun->get_akun()."</th>"; 
                            }
                        }
                    } else {
                        echo "<th>-</th>";
                    }
                ?>
            </tr>
        </thead>
        <tbody class='align-right'>
            <?php //var_dump($akun2); 
                for ($y = 1; $y <= 31; $y++) { ?>
            <tr>
            <td><?php echo $y; ?></td>
            <td align='left'>RENCANA<br>REALISASI<br>DEVIASI (%)</td>
                <?php 
                    $jumlah_deviasi=0;
                    $muncul_deviasi=0;
                    for ($x = 0; $x < $col_akun; $x++) { 
                        $ada_data = false;
                        for ($jml_data = 0; $jml_data < $col; $jml_data++) { 
                            if($data_array[$jml_data]["hari"]==$y && $data_array[$jml_data]["akun"]==$akun2[$x]) {
                                echo "<td bgcolor=''>"
                                    .number_format($data_array[$jml_data]["rpd"])."<br/>"
                                    .number_format($data_array[$jml_data]["realisasi"])."<br/>"
                                    .$data_array[$jml_data]["deviasi"]."</td>";
                                $ada_data = true;
                                $jumlah_deviasi += $data_array[$jml_data]["deviasi"];
                                $muncul_deviasi++;
                            }
                        }
                        if (!$ada_data){
                            echo "<td bgcolor='#8ED6FF'>-<br/>-<br/>-</td>";
                        }
						
                    }  
                    if ($muncul_deviasi>0) {
                        $deviasi_harian = $jumlah_deviasi/$muncul_deviasi;
                    } else {
                        $deviasi_harian = "-";
                    }
                ?>
            <?php 
                if ($deviasi_harian!="-"){
                    echo "<td>".$deviasi_harian."</td>";
                } elseif($deviasi_harian=='0') {
                    echo "<td>".$deviasi_harian."</td>";
                }else {
                    echo "<td bgcolor='#8ED6FF'>".$deviasi_harian."</td>";
                }
            ?>
            </tr>
            <?php } ?>
        </tbody>
    </table>
</div>

<!-- Filter -->
<div class="modal fade" id="modal-app-filter" tabindex="-1" role="dialog" aria-labelledby="app-filter-label" aria-hidden="true">

    <div class="modal-dialog">

        <div class="modal-content">

            <div class="modal-header">

                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Tutup</span></button>
                <h4 class="modal-title" id="app-filter-label"><span class="glyphicon glyphicon-filter"></span> Filter Data</h4>

            </div>

            <form id="filter-form" method="POST" action=<?php echo URL."dataRPD/rekapRPDAkurasiSatker" ?> enctype="multipart/form-data">

                <div class="modal-body">

                    <!-- Paste Isi Fom mulai nangkene -->
                    <div>
                        <div>
                        <div id="wbulan" class='alert alert-danger' style='display:none;'></div>
                        <label class="isian">Bulan: </label>
                        <select class="form-control" type="text" name="bulan" id="bulan">
                        <option value='01' <?php if ($this->d_bulan == '01') {
    echo "selected";
} ?> >Januari</option>
                        <option value='02' <?php if ($this->d_bulan == '02') {
    echo "selected";
} ?> >Februari</option>
                        <option value='03' <?php if ($this->d_bulan == '03') {
    echo "selected";
} ?> >Maret</option>
                        <option value='04' <?php if ($this->d_bulan == '04') {
    echo "selected";
} ?> >April</option>
                        <option value='05' <?php if ($this->d_bulan == '05') {
    echo "selected";
} ?> >Mei</option>
                        <option value='06' <?php if ($this->d_bulan == '06') {
    echo "selected";
} ?> >Juni</option>
                        <option value='07' <?php if ($this->d_bulan == '07') {
    echo "selected";
} ?> >Juli</option>
                        <option value='08' <?php if ($this->d_bulan == '08') {
    echo "selected";
} ?> >Agustus</option>
                        <option value='09' <?php if ($this->d_bulan == '09') {
    echo "selected";
} ?> >September</option>
                        <option value='10' <?php if ($this->d_bulan == '10') {
    echo "selected";
} ?> >Oktober</option>
                        <option value='11' <?php if ($this->d_bulan == '11') {
    echo "selected";
} ?> >November</option>
                        <option value='12' <?php if ($this->d_bulan == '12') {
    echo "selected";
} ?> >Desember</option>
                    </select>
                </div>
                        
                        <?php
                    if (Session::get('role') != SATKER) {
                        echo "<br/>";
                        echo "<div id='wsatker' class='alert alert-danger' style='display:none;'></div>";
                        echo "<label class='isian'>Kode Satker: </label>";
                    }
                    ?>

                    <input class="form-control" type="<?php
                           if (Session::get('role') == SATKER) {
                               echo "hidden";
                           } else {
                               echo "number";
                           }
                           ?>" name="kdsatker" id="kdsatker" size="6" value="<?php
                           if (isset($this->d_kdsatker)) {
                               echo $this->d_kdsatker;
                           }
                           ?>">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" name="submit_file" class="btn btn-primary" style="width: 100%" onClick="return cek_upload()">Kirim</button>
                </div>

            </form>

        </div>

    </div>

</div>

<!-- Skrip -->
<script type="text/javascript" charset="utf-8">
    $(function() {
        hideErrorId();
        hideWarning();
    });



    function hideErrorId() {
        $('.error').fadeOut(0);
    }

    function hideWarning() {

        $('#kdsatker').keyup(function() {
            if (document.getElementById('kdsatker').value != '') {
                $('#wsatker').fadeOut(200);
            }
        });

    }

    function cek_upload() {

        var pattern = '^[0-9]+$';
        var v_kdsatker = document.getElementById('kdsatker').value;

        var jml = 0;
        if ( v_kdsatker == '') {
            $('#wsatker').html('Harap isi salah satu parameter');
            $('#wsatker').fadeIn();
            jml++;
        }


        if (v_kdsatker != '' && v_kdsatker.length != 6) {
            $('#wsatker').html('Kode Satker harus 6 digit');
            $('#wsatker').fadeIn(200);
            jml++;
        }

        if (v_kdsatker != '' && !v_kdsatker.match(pattern)) {
            $('#wsatker').html('Kode Satker harus dalam bentuk angka!');
            $('#wsatker').fadeIn(200);
            jml++;
        }


        if (jml > 0) {
            return false;
        }
    }

</script>
<div class="main-window-segment vertical-padded">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                Pertanyaan menu RPD harap menghubungi PIC Direktorat PKN :</br>
                1. Zakaria, HP : 085226950999, email : zacky.469@gmail.com<br>
                2. Tri Angga Sigit, HP : 081410109462, Email : hanif643@gmail.com
            </div>

        </div>
    </div>
</div>